home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / DBio / DREPrint.cpp < prev    next >
Text File  |  1996-07-05  |  29KB  |  1,071 lines

  1. // DREPrint.cpp
  2. // d.g.gilbert, 1991-95
  3.  
  4.  
  5. #include "DSequence.h"
  6. #include "DSeqList.h"
  7. #include "DSeqDoc.h"
  8. #include "DSeqPrint.h"
  9. #include "DSeqPrintSubs.h"
  10. #include "DREnzyme.h"
  11.  
  12. #include <ncbi.h>
  13. #include <dgg.h>
  14. #include <Dvibrant.h>
  15. #include <DControl.h>
  16. #include <DDialogText.h>
  17. #include <DWindow.h>
  18. #include <DTableView.h>
  19. #include <DApplication.h>
  20. #include <DTask.h>
  21. #include <DTracker.h>
  22. #include <DMenu.h>
  23. #include <DUtil.h>
  24.  
  25.  
  26.  
  27. // add this to ?? dgg.c
  28. inline void RectRgn(Nlm_RegioN rgn, Nlm_RectPtr r)
  29. {     Nlm_LoadRectRgn( rgn, r->left, r->top, r->right, r->bottom); }
  30.  
  31.  
  32.  
  33. // class DDrawZymeTable
  34.  
  35. // class DDrawAllZymeTable
  36.  
  37. // class DDrawNocutZymeTable
  38.  
  39.  
  40.  
  41. DDrawZymeTable::DDrawZymeTable(Nlm_FonT itsFont, DREMap * itsREMap, short rowoffset) :
  42.         fLinelist(NULL)
  43. {
  44.   fName= "";
  45.     fFont= itsFont;
  46.     if (fFont) Nlm_SelectFont(fFont);
  47.     fHeight= Nlm_LineHeight(); 
  48.     fTableTitle= "TABLE of enzymes";
  49.     fRowOffset= rowoffset;
  50. }
  51.  
  52. DDrawZymeTable::~DDrawZymeTable() 
  53.     for (short i=0; i<fLinecount; i++) MemFree( fLinelist[i]);
  54.     MemFree( fLinelist); 
  55. }
  56.  
  57.  
  58. char* DDrawZymeTable::TableLine(short atline) 
  59.     //if (atline == 0) return fTableTitle; else 
  60.     if (atline>=0 && atline<fLinecount) return fLinelist[atline];  
  61.     else return "";
  62. }
  63.  
  64. void  DDrawZymeTable::Clip( Nlm_RecT& r, short row, long startitem, long stopitem,
  65.                                          Nlm_RecT& viewr, Nlm_RegioN cliprgn)
  66. {
  67.     //Nlm_ClipRgn( cliprgn);
  68.     Nlm_RecT clipr= r;
  69.     clipr.left= viewr.left + 10;
  70.     clipr.right= viewr.right - 10;
  71.     clipr.bottom= Min( r.bottom, viewr.bottom);
  72.     clipr.top= Max(r.top, viewr.top);
  73.     Nlm_ClipRect( &clipr);
  74. }
  75.  
  76. void DDrawZymeTable::Draw( Nlm_RecT& r, short row, short col, long startitem, long stopitem)
  77. {
  78.     short     chleft, chvert, atline;
  79.     char  * tabline;
  80.     
  81.     chleft = r.left;
  82.     chvert = r.bottom-2;
  83.     atline = row - fRowOffset;
  84.     tabline= TableLine(atline);
  85.     if (tabline) {
  86.         if (col) { 
  87.           if (StrLen(tabline)>col) tabline += col; // ??? offset TableLine by # cols ?
  88.             else tabline= "";
  89.             }
  90.         if (fFont) Nlm_SelectFont(fFont);
  91.       if (atline == 0) {
  92.             Nlm_MoveTo( chleft, chvert-1);
  93.              Nlm_PaintString( tabline);
  94.             Nlm_MoveTo( r.left, r.bottom-1);
  95.             Nlm_LineTo( r.right, r.bottom-1);
  96.           }
  97.         else if (atline >= 0 && atline < fLinecount) {
  98.             Nlm_MoveTo( chleft, chvert);
  99.             Nlm_PaintString( tabline);
  100.             }
  101.         }
  102. }
  103.  
  104. const char* DDrawZymeTable::Write( short row, short col, long startitem, long stopitem)
  105.     long   len, atline;
  106.     char   * cp;
  107.  
  108.     atline = row - fRowOffset;
  109.     len= Min( kMaxLinebuf, 80);
  110.   if (atline == 0) {
  111.         Nlm_MemFill( fLinebuf, '_', len);
  112.          StrCpy( fLinebuf, TableLine(atline));
  113.          cp= StrChr(fLinebuf, '\0');
  114.          if (cp) *cp= ' ';
  115.       }
  116.     else if (atline >= 0 && atline < fLinecount) {
  117.         Nlm_MemFill( fLinebuf, ' ', len);
  118.         cp = TableLine(atline);
  119.         StrCpy( fLinebuf, cp);
  120.          cp= StrChr(fLinebuf, '\0');
  121.          if (cp) *cp= ' ';
  122.         }
  123.     else {
  124.         Nlm_MemFill( fLinebuf, ' ', len);
  125.         }
  126.     fLinebuf[len]= 0;
  127.     return fLinebuf;
  128. }
  129.  
  130.  
  131.  
  132. DDrawAllZymeTable::DDrawAllZymeTable(Nlm_FonT itsFont, DREMap * itsREMap, short rowoffset) :
  133.         DDrawZymeTable( itsFont, itsREMap, rowoffset)
  134.     fTableTitle= "TABLE of all enzymes";
  135.     if (1) {
  136.         char  * zymeline = NULL;
  137.         long  i, nzymes, linelen, linecount;
  138.         char  buf[128], comma;
  139.  
  140.         nzymes= DREMap::fREnzymes->GetSize();
  141.         linecount= 4 + nzymes / 4;
  142.         fLinelist= (char**) MemNew( linecount * sizeof(char*)); 
  143.         fLinecount= 0;
  144.         sprintf( buf, "  TABLE of All Enzymes  (name: cut count)");
  145.         fLinelist[fLinecount++]= StrDup(buf);
  146.         //sprintf( buf, " ");
  147.         //fLinelist[fLinecount++]= StrDup(buf);
  148.     
  149.         for (i=0, comma = ','; i<nzymes; i++) {
  150.             if (i == nzymes-1) comma= ' ';
  151.             DREnzyme* re= (DREnzyme*) DREMap::fREnzymes->At(i);
  152.             if (re) {
  153.                 //sprintf( buf, "%10s:%3d%c  ", re->fName, re->fCutcount, comma);
  154.                 sprintf( buf, "%9s:%3d  ", re->fName, re->fCutcount, comma);
  155.                 if (zymeline)  
  156.                     zymeline= Dgg_StrExtendCat( &zymeline, buf);
  157.                 else {
  158.                     zymeline= StrDup(buf);
  159.                     }
  160.               linelen= StrLen(zymeline);
  161.                 if (linelen > 70) {
  162.                     fLinelist[fLinecount++]= zymeline;
  163.                     zymeline= NULL;
  164.                     }
  165.                 }
  166.  
  167.           if (fLinecount >= linecount) {
  168.               linecount += 10;
  169.               fLinelist= (char**) Nlm_MemMore( fLinelist, linecount * sizeof(char*));
  170.               }
  171.             }
  172.         if (zymeline) fLinelist[fLinecount++]= zymeline;
  173.         }
  174. }
  175.  
  176.  
  177. DDrawNocutZymeTable::DDrawNocutZymeTable( Nlm_FonT itsFont, DREMap * itsREMap,
  178.              short rowoffset, short mincuts, short maxcuts) :
  179.         DDrawZymeTable( itsFont, itsREMap, rowoffset)
  180.     if (maxcuts) fTableTitle= "TABLE of excluded enzymes";
  181.     else fTableTitle= "TABLE of non-cutting enzymes";
  182.     if (1) {
  183.         char  * zymeline = NULL;
  184.         long  i, nzymes, linelen, linecount;
  185.         char  buf[128], comma;
  186.         Boolean dolist;
  187.         
  188.         nzymes= DREMap::fREnzymes->GetSize();
  189.         linecount= 4 + nzymes / 6;
  190.         fLinelist= (char**) MemNew( linecount * sizeof(char*)); 
  191.         fLinecount= 0;
  192.         if (maxcuts) sprintf( buf, "  TABLE of Excluded Enzymes");
  193.         else sprintf( buf, "  TABLE of Noncutting Enzymes");
  194.         fLinelist[fLinecount++]= StrDup(buf);
  195.         if (maxcuts) {
  196.             sprintf( buf, "  (cut with less than %d or more than %d cuts)", mincuts, maxcuts);
  197.             fLinelist[fLinecount++]= StrDup(buf);
  198.             }
  199.             
  200.         for (i=0, comma = ','; i<nzymes; i++) {
  201.             //if (i == nzymes-1) comma= ' ';
  202.             DREnzyme* re= (DREnzyme*) DREMap::fREnzymes->At(i);
  203.             if (re) {
  204.                 if (maxcuts)  
  205.                     dolist= (re->fCutcount > 0 && (re->fCutcount < mincuts || re->fCutcount > maxcuts));  
  206.                 else 
  207.                     dolist= re->fCutcount == 0;
  208.                 if (dolist) {
  209.                     //sprintf( buf, "%9s%c ", re->fName,comma);
  210.                     sprintf( buf, "%9s ", re->fName);
  211.                     if (zymeline)  
  212.                         zymeline= Dgg_StrExtendCat( &zymeline, buf);
  213.                     else {
  214.                         zymeline= StrDup(buf);
  215.                         }
  216.                   linelen= StrLen(zymeline);
  217.                     if (linelen > 60) {
  218.                         fLinelist[fLinecount++]= zymeline;
  219.                         zymeline= NULL;
  220.                         }
  221.                     }
  222.                 }
  223.  
  224.           if (fLinecount >= linecount) {
  225.               linecount += 10;
  226.               fLinelist= (char**) Nlm_MemMore( fLinelist, linecount * sizeof(char*));
  227.               }
  228.             }
  229.         if (zymeline) fLinelist[fLinecount++]= zymeline;
  230.         }
  231. }
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240. // class DDrawZymeCutTable
  241.  
  242.  
  243. #ifdef WIN_MSWIN
  244. static int LIBCALLBACK
  245. #else
  246. static int
  247. #endif
  248. zymenameCompare(void* a, void* b)
  249. {
  250.     short diff = StringCmp(((DRECutsItem*)a)->fREnzyme->fName, ((DRECutsItem*)b)->fREnzyme->fName);
  251.     if (diff == 0) {
  252.         return ((DRECutsItem*)a)->fSeqIndex - ((DRECutsItem*)b)->fSeqIndex;
  253.         }
  254.     else 
  255.         return diff;
  256. }
  257.  
  258.  
  259.  
  260. DDrawZymeCutTable::DDrawZymeCutTable(Nlm_FonT itsFont, DREMap * itsREMap, short rowoffset) :
  261.         DDrawZymeTable( itsFont, itsREMap, rowoffset),
  262.         fCutList(NULL), fCutcount(0), fCuttersCount(0)
  263.     fTableTitle= "TABLE of cut points";
  264.     if (itsREMap) {
  265.         fCutcount= itsREMap->fCutcount;
  266.         fCuttersCount= itsREMap->fCuttersCount;
  267.         fCutList= (DRECutsItem*) Nlm_MemDup( itsREMap->fSeqCuts, fCutcount * sizeof(DRECutsItem));
  268.         if (fCutList) {
  269.             long  i, at, lastat, linecount, linelen;
  270.             char  *name, *zymeline = NULL, *lastname="";
  271.             char  buf[128];
  272.             
  273.             Nlm_HeapSort( fCutList, fCutcount, sizeof(DRECutsItem), zymenameCompare);
  274.             
  275.             // what if we need more than one line for zyme cut list !!
  276.             for (i=0, linecount= 0; i<fCutcount; i++) {
  277.                 name= fCutList[i].fREnzyme->fName;
  278.                 if (StringCmp(name, lastname)!=0) linecount++;
  279.                 lastname= name;
  280.                 }
  281.           linecount += 3;
  282.             fLinelist= (char**) MemNew( linecount * sizeof(char*)); 
  283.             
  284.             fLinecount= 0;
  285.             sprintf( buf, "  TABLE of Cut Points");
  286.             fLinelist[fLinecount++]= StrDup(buf);
  287.             //sprintf( buf, " ");
  288.             //fLinelist[fLinecount++]= StrDup(buf);
  289.  
  290.           linelen= 0;
  291.             lastname= ""; lastat= -1;
  292.             for (i=0; i<fCutcount && fLinecount < linecount; i++) {
  293.                 name= fCutList[i].fREnzyme->fName;
  294.                 at= fCutList[i].fSeqIndex;
  295.                 if (StringCmp(name, lastname)==0 && linelen<70) { 
  296.                     if (at != lastat) {
  297.                       sprintf(buf, " %d", at);
  298.                         if (zymeline) { 
  299.                           zymeline= Dgg_StrExtendCat( &zymeline, buf);
  300.                           linelen= StrLen(zymeline);
  301.                           }
  302.                       }
  303.                     }
  304.                 else {
  305.                     if (zymeline) fLinelist[fLinecount++]= zymeline;
  306.                     sprintf(buf, "%s: %d", name, at);
  307.                     zymeline= (char*) MemNew(StrLen(buf)+1);
  308.                     Nlm_StringCpy(zymeline, buf);
  309.                     linelen= StrLen(buf);
  310.                     }
  311.                     
  312.                 lastname= name;
  313.                 lastat= at;
  314.               if (fLinecount >= linecount) {
  315.                   linecount += 10;
  316.                   fLinelist= (char**) Nlm_MemMore( fLinelist, linecount * sizeof(char*));
  317.                   }
  318.                 }
  319.             if (zymeline) fLinelist[fLinecount++]= zymeline;
  320.             }
  321.         }
  322. }
  323.  
  324.  
  325. DDrawZymeCutTable::~DDrawZymeCutTable() 
  326.     MemFree( fCutList); 
  327. }
  328.  
  329. char* DDrawZymeCutTable::TableLine(short atline) 
  330.     //if (atline == 0) return fTableTitle; else 
  331.     if (atline>=0 && atline<fLinecount) {
  332.         char * name = fLinelist[atline];
  333.         char * cp= StrChr(name,':'); 
  334.         if (cp) cp++; else cp= name;
  335.         return cp;  
  336.         }
  337.     else return "";
  338. }
  339.  
  340. char* DDrawZymeCutTable::GetName(short row) 
  341.     enum { kNameLen = 80 };
  342.     static char name[kNameLen];
  343.     short atline = row - fRowOffset;
  344.   if (atline == 0) {
  345.         return "ENZYME";
  346.         }
  347.     else if (atline> 0 && atline < fLinecount) {
  348.         StrNCpy(name, fLinelist[atline], kNameLen-1);
  349.         name[kNameLen-1]= 0;
  350.         char* cp= StrChr(name,':'); if (cp) *cp= 0;
  351.         return name;
  352.         }
  353.     else
  354.         return fName; 
  355. }
  356.  
  357.  
  358.  
  359. // class DDrawZymeRow
  360.  
  361.  
  362. DDrawZymeRow::DDrawZymeRow(Nlm_FonT itsFont, DSequence* itsSeq) : 
  363.       fSeq( itsSeq), fGoodMap(false), fCoSeq(NULL), fCutList(NULL),
  364.       fMinCuts(DSeqPrintPrefs::gREMinCuts), 
  365.       fMaxCuts(DSeqPrintPrefs::gREMaxCuts)
  366.   fName= "zyme";
  367.     fFont= itsFont;
  368.     if (fFont) Nlm_SelectFont(fFont);
  369.     fHeight= 4 * Nlm_LineHeight(); // ! need to calc line height for each row !?
  370.     fREMap= new DREMap();
  371.     if (fREMap) {
  372.         fREMap->MapSeq(fSeq);
  373.         fCoSeq= fREMap->fCoSeq;
  374.         fCutList= fREMap->fSeqCuts;
  375.         }
  376.     fGoodMap= (fREMap && fCoSeq && fCutList);
  377. }
  378.  
  379. void  DDrawZymeRow::Clip( Nlm_RecT& r, short row, long startitem, long stopitem,
  380.                                          Nlm_RecT& viewr, Nlm_RegioN cliprgn)
  381. {
  382.     //Nlm_ClipRgn( cliprgn);
  383.     Nlm_RecT clipr= r;
  384.     clipr.left= viewr.left + 10;
  385.     clipr.right= viewr.right - 10;
  386.     clipr.bottom= Min( r.bottom, viewr.bottom);
  387.     clipr.top= Max(r.top, viewr.top);
  388.     Nlm_ClipRect( &clipr);
  389. }
  390.  
  391.  
  392. #define znameCenter 0
  393.  
  394. short DDrawZymeRow::DrawOrMeasure( Nlm_Boolean doDraw, Nlm_RecT& r, short row, long startitem, long stopitem)
  395. {
  396. /*==== 
  397.         gctcggctgctgctcggctg
  398.                 ||        | ||
  399.              abcI    cbaII
  400.                                     hcgX
  401. ====*/
  402.  
  403.     short        nameHeight, rowLeft, rowTop;
  404.     short        chwidth, chleft, ncuts, cutindx;
  405.     short        cuts, wd, ws, rowBot, lasti, i;
  406.     Nlm_PoinT        at;
  407.     Boolean         first,overlap;
  408.     char             * lastzyme, * zymes;    
  409.     Nlm_RecT        fillRect, bRect, cRect;
  410.     Nlm_RegioN     filledArea, aRgn;
  411.  
  412.     if (!fGoodMap) return 0;
  413.     cutindx = 0; //cutindx= fLastZymeCut;
  414.     fREMap->CutsAtBase( startitem, cutindx, ncuts);    //!? don't care if startbase has no cuts
  415.     //fLastZymeCut= cutindx; // ????
  416.     
  417.     if (fFont) Nlm_SelectFont(fFont); 
  418.  
  419.     //atcellh= col;
  420.     nameHeight= Nlm_FontHeight(); // cHeight;
  421.     rowTop= r.top;
  422.     rowLeft= r.left;
  423.     rowBot= rowTop;
  424.     chwidth= (r.right - r.left) / (stopitem - startitem); 
  425.     
  426.     filledArea= Nlm_CreateRgn();
  427.     aRgn= Nlm_CreateRgn();
  428.     
  429.     chleft= rowLeft + kNucSpace;
  430.     Nlm_LoadRect( &fillRect, chleft, rowTop, chleft+1, rowTop+1);
  431.     RectRgn( filledArea, &fillRect); //must start w/ non-empty rgn
  432.     Nlm_MoveTo( chleft, rowTop);
  433.     for ( i= startitem; i<=stopitem; i++) {        
  434.         while (fCutList[cutindx].fSeqIndex < i) cutindx++;  
  435.         first= true;
  436.         lasti= -1; 
  437.         lastzyme= "";
  438.         while (fCutList[cutindx].fSeqIndex == i) {
  439.             zymes= fCutList[cutindx].fREnzyme->fName;
  440.             cuts = fCutList[cutindx].fREnzyme->fCutcount;
  441.             cutindx++;
  442.             if (cuts < fMinCuts || cuts > fMaxCuts)  goto nextZyme;  
  443.                 //! Kludge til we fix REMap to stop dups
  444.             if ( i==lasti && StringCmp(zymes,lastzyme)==0) goto nextZyme; 
  445.             lasti= i; 
  446.             lastzyme= zymes;
  447.             
  448.             if (first) {
  449.                 Nlm_MoveTo( chleft, rowTop);
  450.                 if (doDraw) Nlm_LineTo( chleft, rowTop+2/*kTicSize*/);
  451.                 else Nlm_MoveTo( chleft, rowTop+2);
  452.                 }
  453.  
  454.             ws= Nlm_StringWidth( zymes);
  455.             wd= 2 + ws / 2;
  456.             do {
  457.                 Nlm_GetPen( &at);
  458. #if znameCenter
  459.                 Nlm_LoadRect( &cRect, at.x-wd, at.y, at.x+wd, at.y+nameHeight);
  460. #else
  461.                 Nlm_LoadRect( &cRect, at.x-1, at.y, at.x+ws+1, at.y+nameHeight);
  462. #endif
  463.                 overlap= Nlm_RectInRgn( &cRect, filledArea); 
  464.             
  465.                 if (doDraw && overlap && !first) {
  466.                     //!? replace this w/ draw top to bottom of line, then overwrite zyme names 
  467.                     Nlm_LoadRect( &bRect, at.x, at.y-nameHeight, at.x+1, at.y);
  468.                     if (!Nlm_RectInRgn( &bRect, filledArea)) {
  469.                         Nlm_MoveTo( chleft, at.y-nameHeight+1);
  470.                         Nlm_LineTo( chleft, at.y);
  471.                         }
  472.                     }
  473.                 first= false;
  474.                 Nlm_MoveTo( chleft, at.y+nameHeight);
  475.             } while (overlap);
  476.     
  477.             RectRgn( aRgn, &cRect);
  478.             Nlm_UnionRgn(filledArea, aRgn, filledArea);
  479. #if znameCenter
  480.             Nlm_MoveTo( chleft - (ws / 2), at.y+nameHeight);
  481. #else
  482.             Nlm_MoveTo( chleft, at.y+nameHeight);
  483. #endif
  484.             if (doDraw) {
  485.                 //TextMode(srcCopy);  //erase line overlaps...
  486.                 Nlm_PaintString( zymes); 
  487.                 //TextMode(srcOr);
  488.                 }
  489.             Nlm_GetPen( &at);
  490.             rowBot = Max( rowBot, at.y);   
  491. nextZyme:            
  492.             lasti= i;
  493.             }
  494.             
  495.         //spaceright();
  496.         //chright= chleft + GetColWidth(atCellh) - fColInset;
  497.         //chleft = chright + fColInset;
  498.         //atcellh++;
  499.         chleft += chwidth;
  500.         }
  501.     Nlm_DestroyRgn( filledArea);
  502.     Nlm_DestroyRgn( aRgn);
  503.     return (rowBot - rowTop + 2); //+ 12); /* lineHeight + fudge factor*/    
  504. }
  505.  
  506.  
  507.  
  508.  
  509. const char* DDrawZymeRow::Write( short row, short col, long startitem, long stopitem)
  510. /*==== 
  511.         gctcggctgctgctcggctg
  512.                 ||        | ||
  513.              abcI    cbaII
  514.                                     hcgX
  515. ====*/
  516.  
  517.     short        chleft, ncuts, cutindx;
  518.     short        cuts, ws, lasti;
  519.     Boolean         first,overlap;
  520.     char             * lastzyme, * zymes;    
  521.  
  522.     short    linelen;
  523.     long  len, i, nlines, maxlines;
  524.     char ** lines;
  525.     short zlen, zat, atleft, atline;
  526.  
  527.  
  528.     if (!fGoodMap) return 0;
  529.     len= Min( kMaxLinebuf, stopitem-startitem);
  530.     Nlm_MemFill( fLinebuf, ' ', kMaxLinebuf);
  531.  
  532.     linelen= stopitem-startitem + 5; // +2;
  533.     maxlines= kMaxLinebuf / linelen;
  534.     lines= (char**) MemNew( (maxlines+1) * sizeof(char*));
  535.     for (i=0; i<maxlines; i++) lines[i]= fLinebuf + (linelen * i);
  536.     nlines= 0;
  537.     
  538.     cutindx = 0; //cutindx= fLastZymeCut;
  539.     fREMap->CutsAtBase( startitem, cutindx, ncuts);    //!? don't care if startbase has no cuts
  540.     //fLastZymeCut= cutindx; // ????
  541.         
  542.     for ( i= startitem; i<=stopitem; i++) {        
  543.         while (fCutList[cutindx].fSeqIndex < i) cutindx++;  
  544.         first= true;
  545.         lasti= -1; 
  546.         lastzyme= "";
  547.         chleft= i - startitem;
  548.         while (fCutList[cutindx].fSeqIndex == i) {
  549.             zymes= fCutList[cutindx].fREnzyme->fName;
  550.             cuts = fCutList[cutindx].fREnzyme->fCutcount;
  551.             cutindx++;
  552.             if (cuts < fMinCuts || cuts > fMaxCuts)  goto nextZyme;  
  553.                 //! Kludge til we fix REMap to stop dups
  554.             if ( i==lasti && StringCmp(zymes,lastzyme)==0) goto nextZyme; 
  555.             lasti= i; 
  556.             lastzyme= zymes;
  557.             
  558.             if (first) {
  559.                 lines[0][chleft]= '|';
  560.                 first= false;
  561.                 }
  562.  
  563.             ws= StrLen( zymes);
  564. #if znameCenter
  565.             wd= ws / 2;
  566.             atleft= chleft - wd;
  567. #else
  568.             atleft= chleft;
  569. #endif
  570.             atline= 1;
  571.             do {
  572.               for (zlen=0, zat=atleft, overlap= false; zlen<ws; zlen++, zat++) 
  573.                   if (lines[atline][zat] != ' ') { overlap= true; break; }
  574.               if (overlap) atline++;
  575.             } while (overlap && atline<maxlines);
  576.             MemCpy( lines[atline]+atleft, zymes, ws);
  577.             if (++atline > nlines) nlines= atline;
  578.             first= false;
  579.             
  580. nextZyme:            
  581.             lasti= i;
  582.             }
  583.             
  584.         }
  585.  
  586.     //return  (rowBot - rowTop + 12); /* lineHeight + fudge factor*/    
  587.  
  588.     for (i=1; i<nlines; i++) *(lines[i]-1)= '\n';
  589.     if (nlines) lines[nlines-1][linelen-1]= 0;
  590.     MemFree(lines);
  591.     fLinebuf[kMaxLinebuf]= 0;
  592.     return fLinebuf;
  593. }
  594.  
  595.  
  596.  
  597. short DDrawZymeRow::GetHeight( Nlm_RecT& r, short row, long startitem, long stopitem)
  598.     return DrawOrMeasure( false, r, row, startitem, stopitem);
  599. }
  600.  
  601. void DDrawZymeRow::Draw( Nlm_RecT& r, short row, short col, long startitem, long stopitem)
  602. {
  603.     if (col) { startitem += col; } // ??? 
  604.     (void) DrawOrMeasure( true, r, row, startitem, stopitem);
  605. }
  606.  
  607.  
  608.  
  609.  
  610. // class DDrawORFRow
  611.  
  612.  
  613.  
  614. DDrawORFRow::DDrawORFRow(Nlm_FonT itsFont, DSeqPrintView* itsView, DSequence* itsSeq,
  615.                                  DList* itsStyles, char* name, ulong* colors, short frame) : 
  616.     DDrawSeqRow( itsFont, itsView, itsSeq, itsStyles, name, colors),
  617.     fAAseq(NULL), fFrame( frame) 
  618. {
  619.     Boolean iscomp = frame > 2;
  620.     short   offset = frame % 3;
  621.     sprintf( fNameStore, "orf%d", frame);
  622.     fName= fNameStore;
  623.     if (iscomp) {
  624.         itsSeq->SetSelection( -1,-1);
  625.         itsSeq= itsSeq->Reverse();
  626.             // strange patches...
  627.         if (offset==1) offset= 2;     
  628.         else if (offset==2) offset= 1; 
  629.         if (offset==2) itsSeq->InsertSpacers(itsSeq->LengthF(),offset,'?');   
  630.         }
  631.     itsSeq->SetSelection( offset, itsSeq->LengthF() - offset);
  632.     fAAseq= itsSeq->OnlyORF(' ');
  633.     if (iscomp) { delete itsSeq; itsSeq= NULL; }
  634.     if (fAAseq) {
  635.         fBases= fAAseq->Bases();
  636.         fLength= fAAseq->LengthF();
  637.         if (iscomp) { 
  638.             fAAseq->SetSelection( -1,-1);
  639.             DSequence* unrevAA= fAAseq->Reverse(); 
  640.             delete fAAseq; 
  641.             fAAseq= unrevAA; 
  642.             fBases= fAAseq->Bases();
  643.             fLength= fAAseq->LengthF();
  644.             }
  645.             
  646.         // ?? convert orf bases to some symbol? e.g.,  ...[#####]...
  647.         }
  648. }
  649.  
  650. DDrawORFRow::~DDrawORFRow() 
  651.     if (fAAseq) delete fAAseq; 
  652. }
  653.  
  654. void DDrawORFRow::Draw( Nlm_RecT& r, short row, short col, long startitem, long stopitem)
  655. {
  656.     DDrawSeqRow::Draw(r, row, col, startitem, stopitem );
  657. }
  658.  
  659. const char* DDrawORFRow::Write( short row, short col, long startitem, long stopitem)
  660. /*==== 
  661.         gctcggctgctgctcggctg
  662.                 [---------] [--]
  663.                    [-----------]
  664. ====*/
  665.  
  666.     return DDrawSeqRow::Write( row, col, startitem, stopitem );
  667. }
  668.     
  669.  
  670.  
  671.  
  672.  
  673.  
  674.  
  675.  
  676. // class DREMapPrintView
  677.  
  678.  
  679. DREMapPrintView::DREMapPrintView( long id, DView* itsSuper, DSeqPrintDoc* itsDocument,
  680.                                  DSeqList* itsSeqList, long firstbase, long nbases, long pixwidth, long pixheight):
  681.     DSeqPrintView( id, itsSuper, itsDocument, itsSeqList, firstbase, 
  682.                             nbases, pixwidth, pixheight)
  683.     Initialize();
  684. }
  685.  
  686. void DREMapPrintView::IndexFromRow( long row, long& itemrow, long& seqline, long& startitem, long& stopitem)
  687. {
  688.         // !! modify itemrow to return drawer item row for tables after all of sequence as been drawn
  689.   if (row > fMaxseqrow) {
  690. #if 1
  691.         short i, n = fDrawRowList->GetSize();
  692.         itemrow= fLinesPerParag;
  693.     seqline= row - fMaxseqrow - 2; //??
  694.         for (i= fLinesPerParag; i<n; i++) {
  695.             DDrawMapRow* drawer= (DDrawMapRow*) fDrawRowList->At(i);
  696.             if (drawer && 
  697.                   row >= drawer->fRowOffset && row < drawer->fRowOffset + drawer->fLinecount) { 
  698.                   itemrow= i;
  699.                   seqline= row - drawer->fRowOffset; //??
  700.                   break; 
  701.                     }
  702.             }
  703. #else
  704.     itemrow= fLinesPerParag; // need to adjust this for each spacer, etc...
  705.       if (row > fMaxseqrow + 1) itemrow++;
  706.     seqline= row - fMaxseqrow - 2; //??
  707. #endif
  708.         startitem = seqline;
  709.         stopitem  = startitem+1; //??
  710.       }
  711.   else {
  712.         itemrow    = (row % fLinesPerParag);  
  713.         seqline = (row / fLinesPerParag) * fSeqsperparag;   
  714.         if (fOneseq) seqline += Max( 0, itemrow - fTopPerparag);
  715. #if 1
  716.         startitem = fFirstBase + seqline * fBasesPerLine;
  717.         stopitem  = Min(startitem + fBasesPerLine, fFirstBase+fNbases);
  718. #else
  719.         startitem = seqline * fBasesPerLine;
  720.         stopitem  = startitem + fBasesPerLine;
  721. #endif
  722.         }
  723. }
  724.  
  725. void DREMapPrintView::Initialize()
  726. {
  727.     DSeqPrintView::Initialize();
  728.  
  729.     fSeqLinesPerParag= 1;
  730.     fOneseq= false;
  731.     fDoMidIndex= fDoTopIndex;
  732.     fDoTopIndex= false;
  733.     fDoSeqLine= true;
  734.     fDoCoseqLine= DSeqPrintPrefs::gShowComplement;
  735.     fDoZymeLine= true;
  736.   
  737.     fDoAAline[0]= DSeqPrintPrefs::gShowAA1;
  738.     fDoAAline[1]= DSeqPrintPrefs::gShowAA2;
  739.     fDoAAline[2]= DSeqPrintPrefs::gShowAA3;
  740.     fDoAAline[3]= DSeqPrintPrefs::gShowCompAA1;
  741.     fDoAAline[4]= DSeqPrintPrefs::gShowCompAA2;
  742.     fDoAAline[5]= DSeqPrintPrefs::gShowCompAA3;    
  743.     
  744. }
  745.  
  746. void DREMapPrintView::SetScrollPage()
  747. {
  748.     fItemHeight= Nlm_stdLineHeight;
  749.     DTableView::SetScrollPage();
  750. }
  751.  
  752. void DREMapPrintView::MakeDrawList()
  753. {
  754.     short i, n;
  755.     ulong * colors = NULL;
  756.     DDrawZymeRow * zymerow = NULL;
  757.     DSequence* coseq = NULL;
  758.     Boolean anyamino;
  759.     
  760.     FreeLists();
  761.     //fDrawRowList= FreeListIfObject(fDrawRowList);
  762.     fDrawRowList= new DList(); // NULL, DList::kDeleteObjects << bad
  763.     fDrawRowList->InsertLast(new DDrawSpacer());
  764.     if (fDoTopIndex) 
  765.         fDrawRowList->InsertLast(new DDrawIndexRow(fNumFont,fBaseWidth));
  766.  
  767.     if (fDoZymeLine) {
  768.         fSeq->SetSelection(fFirstBase, fNbases);  // !? zyme map for only selected section
  769.         zymerow= new DDrawZymeRow( fNameFont, fSeq);
  770.         if (zymerow) {
  771.             if (!zymerow->fGoodMap) { delete zymerow; zymerow= NULL; }
  772.             else coseq= zymerow->fCoSeq;
  773.             }
  774.         }
  775.     else if (fDoCoseqLine) {
  776.         fSeq->SetSelection(0,0); // for Complement...
  777.         coseq= fSeq->Complement();
  778.         }
  779.     
  780.     anyamino= false;
  781.     for (i=0; i<6; i++) if (fDoAAline[i]) anyamino= true;
  782.  
  783.     //fStyles= FreeListIfObject(fStyles);
  784.     fStyles= new DList(); // NULL,DList::kDeleteObjects << bad
  785.     n= DStyleTable::fStyles->GetSize();
  786.     for (i=0; i<n; i++) fStyles->InsertLast( DStyleTable::fStyles->At(i));
  787.     
  788. #if 1
  789.     /* if (dospacer) */ fLinesPerParag = 1; fTopPerparag= 1;
  790.     if (fDoTopIndex) { fLinesPerParag++; fTopPerparag++; }
  791.     if (fDoSeqLine)
  792.         fDrawRowList->InsertLast( 
  793.             new DDrawSeqRow( fBaseFont, this, fSeq, fStyles, fSeq->Name(), colors));
  794.     if (fDoSeqLine) { fLinesPerParag++;  }
  795.     if (fDoMidIndex) 
  796.         fDrawRowList->InsertLast(new DDrawIndexRow(fNumFont,fBaseWidth,false));
  797.     if (fDoMidIndex) { fLinesPerParag++;  }
  798.     if (fDoCoseqLine && coseq)
  799.         fDrawRowList->InsertLast( 
  800.             new DDrawSeqRow( fBaseFont, this, coseq, fStyles, "compl", colors));
  801.     if (fDoCoseqLine && coseq) { fLinesPerParag++;}
  802.     if (fDoZymeLine && zymerow)
  803.         fDrawRowList->InsertLast( zymerow);
  804.     if (fDoZymeLine && zymerow) { fLinesPerParag++; }
  805.     if (anyamino)
  806.         fDrawRowList->InsertLast(new DDrawSpacer()); fLinesPerParag++;
  807.         
  808.     for (i= 0; i<3; i++) if (fDoAAline[i])
  809.         fDrawRowList->InsertLast( new DDrawAminoRow( fBaseFont, fSeq, i));
  810.     for (i= 0; i<3; i++) if (fDoAAline[i]) { fLinesPerParag++;  }
  811.     if (fDoMidIndex) 
  812.         fDrawRowList->InsertLast(new DDrawIndexRow(fNumFont,fBaseWidth,false));
  813.     if (fDoMidIndex) { fLinesPerParag++;  }
  814.     for (i= 3; i<6; i++) if (fDoAAline[i] && coseq)
  815.         fDrawRowList->InsertLast( new DDrawAminoRow( fBaseFont, coseq, i));
  816.     for (i= 3; i<6; i++) if (fDoAAline[i]) fLinesPerParag++;
  817.  
  818.     fDrawRowList->InsertLast(new DDrawSpacer()); fLinesPerParag++;
  819.     
  820. #else
  821.     for (i= 0; i<3; i++) if (fDoAAline[i])
  822.         fDrawRowList->InsertLast( new DDrawAminoRow( fBaseFont, fSeq, i));
  823.     if (fDoSeqLine)
  824.         fDrawRowList->InsertLast( 
  825.             new DDrawSeqRow( fBaseFont, this, fSeq, fStyles, fSeq->Name(), colors));
  826.     if (fDoMidIndex) 
  827.         fDrawRowList->InsertLast(new DDrawIndexRow(fNumFont,fBaseWidth,false));
  828.     if (fDoMidIndex) { fLinesPerParag++;  }
  829.     if (fDoCoseqLine && coseq)
  830.         fDrawRowList->InsertLast( 
  831.             new DDrawSeqRow( fBaseFont, this, coseq, fStyles, "compl", colors));
  832.     for (i= 3; i<6; i++) if (fDoAAline[i] && coseq)
  833.         fDrawRowList->InsertLast( new DDrawAminoRow( fBaseFont, coseq, i));
  834.     if (fDoZymeLine && zymerow)
  835.         fDrawRowList->InsertLast( zymerow);
  836.     /* if (dospacer) */ fLinesPerParag = 1; fTopPerparag= 1;
  837.     if (fDoTopIndex) { fLinesPerParag++; fTopPerparag++; }
  838.     for (i= 0; i<3; i++) if (fDoAAline[i]) { fLinesPerParag++; fTopPerparag++; }
  839.     if (fDoSeqLine) { fLinesPerParag++;  }
  840.     if (fDoCoseqLine && coseq) { fLinesPerParag++;}
  841.     for (i= 3; i<6; i++) if (fDoAAline[i]) fLinesPerParag++;
  842.     if (fDoZymeLine) { fLinesPerParag++; }
  843. #endif
  844.  
  845.     fMaxseqrow= 1 + (fMaxbases / fBasesPerLine);
  846.     fMaxseqrow *= fLinesPerParag;
  847.     if (zymerow && DSeqPrintPrefs::gShowCutpoints) {
  848.         fDrawRowList->InsertLast(new DDrawSpacer()); fExtrarows++;
  849.         DDrawZymeCutTable* ztab= new DDrawZymeCutTable( gTextFont/*fNumFont*/,  
  850.                                                                     zymerow->fREMap, fMaxseqrow+fExtrarows);  
  851.         fDrawRowList->InsertLast( ztab);  
  852.     fExtrarows += ztab->fLinecount + 1;
  853.     }
  854.     if (zymerow && DSeqPrintPrefs::gShowAllZymes) {
  855.         fDrawRowList->InsertLast(new DDrawSpacer()); fExtrarows++;
  856.         DDrawAllZymeTable* ztab= new DDrawAllZymeTable( gTextFont, zymerow->fREMap, 
  857.                                                                         fMaxseqrow+fExtrarows);  
  858.         fDrawRowList->InsertLast( ztab);  
  859.     fExtrarows += ztab->fLinecount + 1;
  860.     }
  861.     if (zymerow && DSeqPrintPrefs::gShowNoncutters) {
  862.         fDrawRowList->InsertLast(new DDrawSpacer()); fExtrarows++;
  863.         DDrawNocutZymeTable* ztab= new DDrawNocutZymeTable( gTextFont, zymerow->fREMap, 
  864.                                                                         fMaxseqrow+fExtrarows);  
  865.         fDrawRowList->InsertLast( ztab);  
  866.     fExtrarows += ztab->fLinecount + 1;
  867.     }
  868.     if (zymerow && DSeqPrintPrefs::gShowExcludedCutters) {
  869.         fDrawRowList->InsertLast(new DDrawSpacer()); fExtrarows++;
  870.         DDrawNocutZymeTable* ztab= new DDrawNocutZymeTable( gTextFont, zymerow->fREMap, 
  871.                                                                         fMaxseqrow+fExtrarows, 
  872.                                                                         DSeqPrintPrefs::gREMinCuts,
  873.                                                                         DSeqPrintPrefs::gREMaxCuts);  
  874.         fDrawRowList->InsertLast( ztab);  
  875.     fExtrarows += ztab->fLinecount + 1;
  876.     }
  877.      
  878. }
  879.  
  880.  
  881.  
  882. // class DREMapPrintDoc
  883.  
  884. DREMapPrintDoc::DREMapPrintDoc( long id, DSeqDoc* itsDoc, DSeqList* itsSeqList, long firstbase, long nbases) :
  885.     DSeqPrintDoc( id, itsDoc, itsSeqList, firstbase, nbases)
  886. {
  887.     short width= 450, height= 350;
  888.     //super->GetNextPosition( &nps);
  889.     //width = MAX( 40, fgWinRect.right - fgWinRect.left) - Nlm_vScrollBarWidth  - nps.x; 
  890.     //height= MAX( 60, fgWinRect.bottom - fgWinRect.top) - Nlm_hScrollBarHeight - nps.y;   
  891.     fView= new DREMapPrintView(0,this,this,fSeqList,fFirstBase,fNbases,width,height);
  892.  
  893.     char title[256];
  894.     DSequence * aSeq= (DSequence*) fSeqList->At(0);
  895.     if (aSeq)  
  896.         StrCpy(title, aSeq->Name());
  897.     else
  898.         itsDoc->GetTitle( title, sizeof(title)); 
  899.     StrCat( title, " Restr. Map");
  900.     SetTitle( title);
  901. }
  902.  
  903.  
  904.  
  905.  
  906.  
  907.  
  908.  
  909.  
  910. // class DAsmPrintView
  911.  
  912.  
  913. DAsmPrintView::DAsmPrintView( long id, DView* itsSuper, DSeqPrintDoc* itsDocument,
  914.                                  DSeqList* itsSeqList, long firstbase, long nbases, long pixwidth, long pixheight):
  915.     DSeqPrintView( id, itsSuper, itsDocument, itsSeqList, firstbase, 
  916.                             nbases, pixwidth, pixheight)
  917.     Initialize();
  918. }
  919.  
  920. void DAsmPrintView::IndexFromRow( long row, long& itemrow, long& seqline, long& startitem, long& stopitem)
  921. {
  922.         // !! modify itemrow to return drawer item row for tables after all of sequence as been drawn
  923.   if (row > fMaxseqrow) {
  924.         short i, n = fDrawRowList->GetSize();
  925.         itemrow= fLinesPerParag;
  926.     seqline= row - fMaxseqrow - 2; //??
  927.         for (i= fLinesPerParag; i<n; i++) {
  928.             DDrawMapRow* drawer= (DDrawMapRow*) fDrawRowList->At(i);
  929.             if (drawer && 
  930.                   row >= drawer->fRowOffset && row < drawer->fRowOffset + drawer->fLinecount) { 
  931.                   itemrow= i;
  932.                   seqline= row - drawer->fRowOffset; //??
  933.                   break; 
  934.                     }
  935.             }
  936.         startitem = seqline;
  937.         stopitem  = startitem+1; //??
  938.       }
  939.   else {
  940.         itemrow    = (row % fLinesPerParag);  
  941.         seqline = (row / fLinesPerParag) * fSeqsperparag;   
  942.         if (fOneseq) seqline += Max( 0, itemrow - fTopPerparag);
  943.         startitem = fFirstBase + seqline * fBasesPerLine;
  944.         stopitem  = Min(startitem + fBasesPerLine, fFirstBase+fNbases);
  945.         }
  946. }
  947.  
  948. void DAsmPrintView::Initialize()
  949. {
  950.     DSeqPrintView::Initialize();
  951.  
  952.     fSeqLinesPerParag= 1;
  953.     fOneseq= false;
  954.     fDoMidIndex= fDoTopIndex;
  955.     fDoTopIndex= false;
  956.     fDoSeqLine= true;
  957.     fDoCoseqLine= DSeqPrintPrefs::gShowComplement;
  958.     fDoZymeLine= true;
  959.   
  960.     fDoAAline[0]= false;
  961.     fDoAAline[1]= false;
  962.     fDoAAline[2]= false;
  963.     fDoAAline[3]= false;
  964.     fDoAAline[4]= false;
  965.     fDoAAline[5]= false;    
  966.     
  967. }
  968.  
  969. void DAsmPrintView::SetScrollPage()
  970. {
  971.     fItemHeight= Nlm_stdLineHeight;
  972.     DTableView::SetScrollPage();
  973. }
  974.  
  975. void DAsmPrintView::MakeDrawList()
  976. {
  977.     short i, n;
  978.     ulong * colors = NULL;
  979.     DDrawZymeRow * zymerow = NULL;
  980.     DSequence* coseq = NULL;
  981.     Boolean anyamino;
  982.     
  983.     FreeLists();
  984.     fDrawRowList= new DList(); // NULL, DList::kDeleteObjects << bad
  985.     fDrawRowList->InsertLast(new DDrawSpacer());
  986.     if (fDoTopIndex) 
  987.         fDrawRowList->InsertLast(new DDrawIndexRow(fNumFont,fBaseWidth));
  988.  
  989.     if (fDoZymeLine) {
  990.         fSeq->SetSelection(fFirstBase, fNbases);  // !? zyme map for only selected section
  991.         zymerow= new DDrawZymeRow( fNameFont, fSeq);
  992.         if (zymerow) {
  993.             if (!zymerow->fGoodMap) { delete zymerow; zymerow= NULL; }
  994.             else coseq= zymerow->fCoSeq;
  995.             }
  996.         }
  997.     else if (fDoCoseqLine) {
  998.         fSeq->SetSelection(0,0); // for Complement...
  999.         coseq= fSeq->Complement();
  1000.         }
  1001.     
  1002.     anyamino= false;
  1003.  
  1004.     fStyles= new DList(); // NULL,DList::kDeleteObjects << bad
  1005.     n= DStyleTable::fStyles->GetSize();
  1006.     for (i=0; i<n; i++) fStyles->InsertLast( DStyleTable::fStyles->At(i));
  1007.     
  1008.     /* if (dospacer) */ fLinesPerParag = 1; fTopPerparag= 1;
  1009.     if (fDoTopIndex) { fLinesPerParag++; fTopPerparag++; }
  1010.     if (fDoSeqLine)
  1011.         fDrawRowList->InsertLast( 
  1012.             new DDrawSeqRow( fBaseFont, this, fSeq, fStyles, fSeq->Name(), colors));
  1013.     if (fDoSeqLine) { fLinesPerParag++;  }
  1014.     if (fDoMidIndex) 
  1015.         fDrawRowList->InsertLast(new DDrawIndexRow(fNumFont,fBaseWidth,false));
  1016.     if (fDoMidIndex) { fLinesPerParag++;  }
  1017.     if (fDoCoseqLine && coseq)
  1018.         fDrawRowList->InsertLast( 
  1019.             new DDrawSeqRow( fBaseFont, this, coseq, fStyles, "compl", colors));
  1020.     if (fDoCoseqLine && coseq) { fLinesPerParag++;}
  1021.     if (fDoZymeLine && zymerow)
  1022.         fDrawRowList->InsertLast( zymerow);
  1023.     if (fDoZymeLine && zymerow) { fLinesPerParag++; }
  1024.  
  1025.     fDrawRowList->InsertLast(new DDrawSpacer()); fLinesPerParag++;
  1026.     
  1027.     fMaxseqrow= 1 + (fMaxbases / fBasesPerLine);
  1028.     fMaxseqrow *= fLinesPerParag;
  1029.  
  1030.      
  1031. }
  1032.  
  1033.  
  1034.  
  1035. // class DAsmPrintDoc 
  1036.  
  1037. DAsmPrintDoc::DAsmPrintDoc( long id, DSeqDoc* itsDoc, DSeqList* itsSeqList, long firstbase, long nbases) :
  1038.     DSeqPrintDoc( id, itsDoc, itsSeqList, firstbase, nbases)
  1039. {
  1040.     short width= 450, height= 350;
  1041.     fView= new DAsmPrintView(0,this,this,fSeqList,fFirstBase,fNbases,width,height);
  1042.  
  1043.     char title[256];
  1044.     DSequence * aSeq= (DSequence*) fSeqList->At(0);
  1045.     if (aSeq)  
  1046.         StrCpy(title, aSeq->Name());
  1047.     else
  1048.         itsDoc->GetTitle( title, sizeof(title)); 
  1049.     StrCat( title, " Assembly");
  1050.     SetTitle( title);
  1051. }
  1052.  
  1053.  
  1054.  
  1055.